<?php

/**
 * map actions.
 *
 * @package    Redsea20
 * @subpackage map
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class mapActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {



   
  }

public function executeSearch(sfWebRequest $request)
{
    
    

     $str="";
     $this->pgTag="";
      if ($this->getRequestParameter('search')!=null && $this->getRequestParameter('search')!="")
      {
              $str= explode("flag_search_d_pg_t", $this->getRequestParameter('search'));
              
                if ($str[1]!=null && ($str[1]=="BIO" || $str[1]=="ALL"))
                {
                    
                  $this->pgTag=$str[1];
                  $this->biodata = new sfDoctrinePager('', '100');
                  $q = Doctrine_Query::create()
                  ->select('odd.speciesid,s.species as spname')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Species s')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Entity rr')
                  ->where('odd.tag LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('s.species LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('r.title LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('o.location LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('rr.Firstname LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('rr.Lastname LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('substr((cast(o.observationdate as char(800))),1,10) LIKE ?', '%'.$str[0].'%')
                  ->groupBy('odd.speciesid');

                  $this->biodata->setQuery($q);
                  if ($str[2]!=null && $str[2]!="")
                    {
                        $this->biodata->setPage($str[2]);
                        $this->biodata->init();
                    }
                  else {
                        $this->biodata->setPage('1');
                        $this->biodata->init();
                    }

                }
                 if ($str[1]!=null && ($str[1]=="NONBIO" || $str[1]=="ALL"))
                {
                    
                  $this->pgTag=$str[1];
                  $this->nonbiodata = new sfDoctrinePager('', '100');
                  $q = Doctrine_Query::create()
//                  ->select('o.location,o.lat,o.lng,od.observationid')
//		  ->from('observationdepth od')
//                  ->leftJoin('od.Observation o')
//                  ->leftJoin('o.Research r')
//                  ->leftJoin('r.Entity rr')
//                  ->where("od.id NOT IN (SELECT odd.observationdepthid FROM observationdepthdetail odd)")
//                  ->andWhere("(rr.Firstname like '%".$str[0]."%' OR rr.Lastname like '%".$str[0]."%' OR r.title like '%".$str[0]."%' OR o.location like '%".$str[0]."%' OR substr((cast(o.observationdate as char(800))),1,10) like '%".$str[0]."%')")
//                  ->groupBy('o.location')
//                  ->groupBy('o.lat')
//                  ->groupBy('o.lng')
//                  ->groupBy('od.observationid');
                  ->select('a.attributename,a.id,ada.id')
		  ->from('observationdepthattribute ada')
                  ->leftJoin('ada.Attribute a')
                  ->leftJoin('ada.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Entity rr')
                  ->where("ada.attributevalue > 0 ")
                  ->andWhere("(a.attributename like '%".$str[0]."%' OR rr.Firstname like '%".$str[0]."%' OR rr.Lastname like '%".$str[0]."%' OR r.title like '%".$str[0]."%' OR o.location like '%".$str[0]."%' OR substr((cast(o.observationdate as char(800))),1,10) like '%".$str[0]."%')")
                  ->groupBy('a.attributename');


                  $this->nonbiodata->setQuery($q);
                  if ($str[2]!=null && $str[2]!="")
                    {
                        $this->nonbiodata->setPage($str[2]);
                        $this->nonbiodata->init();
                    }
                  else {
                        $this->nonbiodata->setPage('1');
                        $this->nonbiodata->init();
                    }
                }
                if ($str[1]!=null && ($str[1]=="OVERLAY" || $str[1]=="ALL"))
                {
 
                  $this->pgTag=$str[1];
                  $this->overlaydata = new sfDoctrinePager('', '100');
                  $q = Doctrine_Query::create()
                  ->select('ro.id,ro.overlaytitle')
                  ->from('researchoverlay ro')
		  ->leftJoin('ro.Research r')
                  ->leftJoin('r.Entity rr')
                   ->where('r.title LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('ro.overlaytitle LIKE ?', '%'.$str[0].'%')
                   ->ORwhere('rr.Firstname LIKE ?', '%'.$str[0].'%')
                  ->ORwhere('rr.Lastname LIKE ?', '%'.$str[0].'%');

                  $this->overlaydata->setQuery($q);
                  if ($str[2]!=null && $str[2]!="")
                    {
                        $this->overlaydata->setPage($str[2]);
                        $this->overlaydata->init();
                    }
                  else {
                        $this->overlaydata->setPage('1');
                        $this->overlaydata->init();
                    }
                }
    }
      

}

public function executeHistory(sfWebRequest $request)
  {
    $str="";
      if ($this->getRequestParameter('searchhistory')!=null && $this->getRequestParameter('searchhistory')!="")
      {

          $str= explode("OLY", $this->getRequestParameter('searchhistory'));

          if ($str[0]!=null && $str[0]!="")
          {
          $this->researchs=Doctrine_Query::create()

                  ->select('odd.id,s.species,o.location,od.observationdepth,odd.quantity,o.observationdate,odd.tag')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Species s')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Entity rr')
                  ->where('odd.id In ('.$str[0].')')
                  ->orderby('o.Location,s.species')
                  ->execute();
          }

           if ($str[2]!=null && $str[2]!="")
          {

           $this->researchsattribute=Doctrine_Query::create()
		  ->from('observationdepth od')
		  ->where('od.id In ('.$str[2].')')
                  ->execute();

          }


          if ($str[1]!=null && $str[1]!="")
          {
           $this->overlayImage=Doctrine_Query::create()
                  ->from('researchoverlay ro')
                   ->where('ro.id In ('.$str[1].')')
                   ->execute();
          }
      }




  }

  public function executeAutocomplete(sfWebRequest $request)
  {



          $Species=Doctrine_Query::create()
                  ->select('s.id,s.Species')
                  ->from('species s')
                  ->orderby('s.species')
                  ->execute();
           $Attribute=Doctrine_Query::create()
                  ->select('a.id,a.attributename')
                  ->from('attribute a')
                  ->orderby('a.attributename')
                  ->execute();
            $Overlay=Doctrine_Query::create()
                  ->select('o.id,o.overlaytitle')
                  ->from('researchoverlay o')
                  ->orderby('o.overlaytitle')
                  ->execute();
          $str="";
                   foreach($Species as $r)
                   {
                    $str=$str.$r->getSpecies()."###";
                   }
                   foreach($Attribute as $r)
                   {
                    $str=$str.$r->getAttributename()."###";
                   }
                   foreach($Overlay as $r)
                   {
                    $str=$str.$r->getOverlaytitle()."###";
                   }

                    echo $str;

		  return sfView::NONE;
  }


  
public function executeOverlay_Image(sfWebRequest $request)
  {
     $overlayid = 0;
      /**
       * IF PASSED PARAMETER IS NULL/0, THEN GET THE ID FROM SESSION
       */
      if($this->getRequestParameter('overlayid') != null && $this->getRequestParameter('overlayid') != '0')
      {
          $overlayid = $this->getRequestParameter('overlayid');
      $overlayList = Doctrine_Core::getTable('researchoverlay');
      $img = $overlayList->find($overlayid);
      //$entity = $entityList->find($this->getUser()->getAttribute('userid'));


      echo $img["overlayimage"];
      }


      return sfView::NONE;
  }
 
  public function executeMap_Data(sfWebRequest $request)
  {
      $str="";
      
         $str=explode("flg_bio_and_nonbio_map_point", $this->getRequestParameter('search'));
          //$str=$this->getRequestParameter('search');
          if ($str[0]!=null && $str[0]!="")
          {
            $this->observationList = Doctrine_Query::create()
                                ->select('o.lat,o.lng,o.id')
                                ->from('observation o')
                                ->leftJoin('o.Observationdepth od')
                                ->leftJoin('od.Observationdepthdetail odd')
                                ->where('odd.speciesid In ('.$str[0].')')
                                ->addWhere('odd.quantity>0')
                                ->execute();
          }
          if ($str[1]!=null && $str[1]!="")
          {
            $this->observationList_non = Doctrine_Query::create()
                                ->select('o.lat,o.lng,o.id')
                                ->from('observation o')
                                ->leftJoin('o.Observationdepth od')
                                ->leftJoin('od.Observationdepthattribute oda')
                                ->where('oda.attributeid In ('.$str[1].')')
                                ->execute();
          }
          if(($str[0]==null || $str[0]=="")&&($str[1]==null || $str[1]==""))
          {
              $this->observationList = Doctrine_Query::create()
                                ->select('o.lat,o.lng,o.id')
                                ->from('observation o')
                                ->execute();
          }
      
 
          
 
        echo "<markers>";

        foreach($this->observationList as $r){
            echo "<marker ";
            $tag = "lat";
            echo ($tag. '="'.$r->getLat().'" ');
            $tag = "lng";
            echo ($tag. '="'.$r->getLng().'" ');
            $tag = "Location";
            echo ($tag. '="'.$r->getId().'" ');
            $tag = "str";
            echo ($tag. '="'.$str.'" ');
            echo (' />');
        }
        foreach($this->observationList_non as $r){
            echo "<marker ";
            $tag = "lat";
            echo ($tag. '="'.$r->getLat().'" ');
            $tag = "lng";
            echo ($tag. '="'.$r->getLng().'" ');
            $tag = "Location";
            echo ($tag. '="'.$r->getId().'" ');
            $tag = "str";
            echo ($tag. '="'.$str.'" ');
            echo (' />');
        }
        echo "</markers>";

        return sfView::NONE;
  }

  public function executeOverlay_Data(sfWebRequest $request)
  {
      $str="";
      if ($this->getRequestParameter('search')!=null && $this->getRequestParameter('search')!="")
      {

          $str=$this->getRequestParameter('search');
            $this->overlayData = Doctrine_Query::create()
                  ->from('researchoverlay ro')
		  ->where('ro.id In ('.$str.')')
                  ->execute();
      }

        echo "<markers>";

        foreach($this->overlayData as $r){
            echo "<marker ";
            $tag = "id";
            echo ($tag. '="'.$r->getId().'" ');
            $tag = "nlat";
            echo ($tag. '="'.$r->getNlat().'" ');
            $tag = "wlng";
            echo ($tag. '="'.$r->getWlng().'" ');
            $tag = "slat";
            echo ($tag. '="'.$r->getSlat().'" ');
            $tag = "elng";
            echo ($tag. '="'.$r->getElng().'" ');
            echo (' />');
        }
        echo "</markers>";

        return sfView::NONE;
  }

  public function executeSearchdetailgridbio(sfWebRequest $request)
  {


      $str= explode("flag_search_d_pg_t", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
            $this->griddetail = new sfDoctrinePager('', '100');
                  $q=Doctrine_Query::create()
                  ->select('odd.id,odd.quantity,od.observationdepth,o.location,o.observationdate,o.observationtime,odd.tag,u.unit')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('od.Unit u')
                  ->leftJoin('odd.Species s')
                  ->where('s.id in ('.$str[0].')')
                  ->orderby('s.species,o.location');

                  $this->griddetail->setQuery($q);
                  if ($str[1]!=null && $str[1]!="")
                    {
                        $this->griddetail->setPage($str[1]);
                        $this->griddetail->init();
                    }
                  else {
                        $this->griddetail->setPage('1');
                        $this->griddetail->init();
                    }

            }
  }


  public function executeSearchdetailgridloadattribute(sfWebRequest $request)
  {


      $str= $this->getRequestParameter('search');


        if ($str !=null && $str!="")
            {
                    $this->gridattribute=Doctrine_Query::create()
                  ->select('oda.id,oda.attributevalue,u.unit,a.attributename,r.title,r.citation,e.firstname,o.observationdate,od.observationid')
                  ->from('observationdepthattribute oda')
                  ->leftJoin('oda.Attribute a')
                  ->leftJoin('oda.Unit u')
                  ->leftJoin('oda.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Entity e')
                   ->where('od.id = ?', $str)
                  ->orderby('a.attributename')->execute();

                  

            }
  }



  public function executeSearchdetailgridnonbio(sfWebRequest $request)
  {


      $str= explode("flag_search_d_pg_t", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
            $this->griddetail = new sfDoctrinePager('', '50');
                  $q=Doctrine_Query::create()
                  ->select('od.id,od.observationdepth,o.location,o.observationdate,o.observationtime')
                  ->from('observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('od.Observationdepthattribute oda')
                  ->where('oda.attributeid in ('.$str[0].')')
                  ->orderby('o.location');

                  $this->griddetail->setQuery($q);
                  if ($str[1]!=null && $str[1]!="")
                    {
                        $this->griddetail->setPage($str[1]);
                        $this->griddetail->init();
                    }
                  else {
                        $this->griddetail->setPage('1');
                        $this->griddetail->init();
                    }

            }
  }

public function executeSearchdetailgridoverlay(sfWebRequest $request)
  {


      $str= explode("flag_search_d_pg_t", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
            $this->griddetail = new sfDoctrinePager('', '3');
                  $q=Doctrine_Query::create()
                  ->select('or.id,or.overlaytitle,or.slat,or.wlng,or.nlat,or.elng,r.title,r.citation,e.firstname')
                  ->from('researchoverlay or')
                  ->leftJoin('or.Research r')
                  ->leftJoin('r.Entity e')
                  ->where('or.id in ('.$str[0].')');

                  $this->griddetail->setQuery($q);
                  if ($str[1]!=null && $str[1]!="")
                    {
                        $this->griddetail->setPage($str[1]);
                        $this->griddetail->init();
                    }
                  else {
                        $this->griddetail->setPage('1');
                        $this->griddetail->init();
                    }

            }
  }

public function executeSearchcitation(sfWebRequest $request)
  {


      $str= explode("flag_search_citation", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
                  if ($str[1] =="BIO")
                  {
                  $this->flgCitation="BIO";
                  $this->Biocitation=Doctrine_Query::create()
                  ->select('r.citation,odd.id,o.id,od.id')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('odd.Species s')
                  ->where('s.id in ('.$str[0].')')
                  ->groupBy('r.citation')
                  ->execute();
                  }
                  else if ($str[1] =="NONBIO")
                  {
                  $this->flgCitation="NONBIO";
                  $this->NONBiocitation=Doctrine_Query::create()
                  ->select('r.citation,o.id,od.id')
                  ->from('observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->where('od.id in ('.$str[0].')')
                  ->groupBy('r.citation')
                  ->execute();
                  }

                  else if ($str[1] =="OVERLAY")
                  {
                  $this->flgCitation="OVERLAY";
                  $this->Overlaycitation=Doctrine_Query::create()
                  ->select('ro.id,r.citation')
                  ->from('researchoverlay ro')
		  ->leftJoin('ro.Research r')
                  ->where('ro.id in ('.$str[0].')')
                  ->groupBy('r.citation')
                  ->execute();
                  }

            }

            
  }
  public function executeBiographdata(sfWebRequest $request)
  {
      $params = "";// "375,374";
      $strtmp="";
    if ($this->getRequestParameter('search') !=null && $this->getRequestParameter('search') != "")
    {

        $params= explode("flg_graph_filter", $this->getRequestParameter('search'));
$depthv= "";
if ($params[3]!= null && $params[3]!= "null" && $params[3]!= "All" ){$depthv= ' and od.observationdepth = '. $params[3];}
        if ($params[1]!= null && $params[2]!= null && $params[1]== "location" && $params[2]!= "All")
        {
            $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.location,odd.quantity,s.species,o.lat,o.lng,o.observationdate,o.remarks')
                  ->from('observationdepthdetail odd')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('odd.Species s')
                  ->where('s.id In ('.$params[0].')')
                  ->andWhere('odd.quantity>0'.$depthv)
                  ->andWhere('substr((cast(o.observationdate as char(800))),1,10) LIKE ?', '%'.$params[2].'%')
                  ->orderBy('o.location')
                  ->execute();
        }
        else if ($params[1]!= null && $params[2]!= null && $params[1]== "year" && $params[2]!= "All")
        {
            $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.location,odd.quantity,s.species,o.lat,o.lng,o.observationdate,o.remarks')
                  ->from('observationdepthdetail odd')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('odd.Species s')
                  ->where('s.id In ('.$params[0].')')
                  ->andWhere('odd.quantity>0'.$depthv)
                  ->andWhere('o.location LIKE ?', $params[2])
                  ->orderBy('o.observationdate')
                  ->execute();
        }
        else
        {
                  $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.location,odd.quantity,s.species,o.lat,o.lng,o.observationdate,o.remarks')
                  ->from('observationdepthdetail odd')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('odd.Species s')
                  ->where('s.id In ('.$params[0].')')
                  ->andWhere('odd.quantity>0' . $depthv)
                  ->orderBy($params[1])
                  ->execute();
        }


    }

    $output="";
    foreach($this->chartDetail as $item){
        $time = strtotime($item->Observationdepth->Observation["observationdate"]);
        $year=date('Y', $time);


        $output= $output.$item->Species["species"].":".$item->Observationdepth->Observation["location"].":".$item["quantity"].":".$item->Observationdepth->Observation["lat"].":".$item->Observationdepth->Observation["lng"].":".$year.":".$item->Observationdepth->Observation["remarks"].":".$item->Observationdepth->Observation["observationdate"]."|";



    }
    echo $output;

    return sfView::NONE;
  }
public function executeNonbiographdata(sfWebRequest $request)
  {
      $params = "";// "375,374";
      $strtmp="";
    if ($this->getRequestParameter('search') !=null && $this->getRequestParameter('search') != "")
    {

        $params= explode("flg_graph_filter", $this->getRequestParameter('search'));
$depthv= "";
$unitv= "";
if ($params[3]!= null && $params[3]!= "null" && $params[3]!= "All" ){$depthv= ' and od.observationdepth = '. $params[3];}
if ($params[4]!= null && $params[4]!= "null" && $params[4]!= "All" ){$unitv= " and u.unit = '". $params[4]."'";}

        if ($params[1]!= null && $params[2]!= null && $params[1]== "observationdepth" && $params[2]!= "All")
        {
            $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.location,odd.attributevalue,a.attributename,o.lat,o.lng,o.observationdate,o.remarks')
                  ->from('observationdepthattribute odd')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('odd.Attribute a')
                  ->leftJoin('odd.Unit u')
                  ->where('a.id In ('.$params[0].')')
                  ->andWhere('substr((cast(o.observationdate as char(800))),1,10) LIKE ?', '%'.$params[2].'%')
                  ->andWhere('odd.attributevalue>0 ' .$depthv . $unitv)
                  ->orderBy('od.observationdepth')
                  ->execute();
        }
        else if ($params[1]!= null && $params[2]!= null && $params[1]== "year" && $params[2]!= "All")
        {
            $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.location,odd.attributevalue,a.attributename,o.lat,o.lng,o.observationdate,o.remarks')
                  ->from('observationdepthattribute odd')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('odd.Attribute a')
                  ->leftJoin('odd.Unit u')
                  ->where('a.id In ('.$params[0].')')
                  ->andWhere('o.location LIKE ?', $params[2])
                  ->andWhere('odd.attributevalue>0 ' .$depthv . $unitv)
                  ->orderBy('o.observationdate')
                  ->execute();
        }
        else
        {
                  $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.location,odd.attributevalue,a.attributename,o.lat,o.lng,o.observationdate,odu.unit,o.remarks')
                  ->from('observationdepthattribute odd')
		  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('odd.Attribute a')
                  ->leftJoin('odd.Unit u')
                  ->leftJoin('od.Unit odu')
                  ->where('a.id In ('.$params[0].')')
                  ->andWhere('odd.attributevalue>0 ' .$depthv . $unitv)
                  ->orderBy($params[1])
                  ->execute();
        }


    }


    $output="";
    foreach($this->chartDetail as $item){
        $time = strtotime($item->Observationdepth->Observation["observationdate"]);
        $year=date('Y', $time);


        $output= $output.$item->Attribute["attributename"].":".$item->Observationdepth->Observation["location"].":".$item["attributevalue"].":".$item->Observationdepth->Observation["lat"].":".$item->Observationdepth->Observation["lng"].":".$year.":".$item->Observationdepth["observationdepth"].":".$item->Unit["unit"].":".$item->Observationdepth->Unit["unit"].":".$item->Observationdepth->Observation["observationdate"].":".$item->Observationdepth->Observation["remarks"]."|";



    }
    echo $output;

    return sfView::NONE;
  }

  public function executeLoadsearchresultlocations(sfWebRequest $request)
  {
     $str= explode("flag_search_loadsearchresultlocations", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
                  if ($str[1] =="BIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.id,o.location')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->where('odd.speciesid in ('.$str[0].')')
                  ->groupBy('o.location')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $strtmp=$strtmp.'<option>'.$t->Observationdepth->Observation["location"].'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }
                  else if ($str[1] =="NONBIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.id,o.location')
                  ->from('observationdepthattribute odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->where('odd.attributeid in ('.$str[0].')')
                  ->groupBy('o.location')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $strtmp=$strtmp.'<option>'.$t->Observationdepth->Observation["location"].'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }
//
//                  else if ($str[1] =="OVERLAY")
//                  {
//                  $this->flgCitation="OVERLAY";
//                  $this->Overlaycitation=Doctrine_Query::create()
//                  ->select('ro.id,r.citation')
//                  ->from('researchoverlay ro')
//		  ->leftJoin('ro.Research r')
//                  ->where('ro.id in ('.$str[0].')')
//                  ->groupBy('r.citation')
//                  ->execute();
//                  }

            }

  }

 public function executeLoadsearchresultyears(sfWebRequest $request)
  {
     $str= explode("flag_search_loadsearchresultyears", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
                  if ($str[1] =="BIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.id,YEAR(o.observationdate)')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->where('odd.speciesid in ('.$str[0].')')
                  ->groupBy('YEAR(o.observationdate)')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $time = strtotime($t->Observationdepth->Observation["observationdate"]);
                    $year=date('Y', $time);
                      $strtmp=$strtmp.'<option>'.$year.'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }
                  else if ($str[1] =="NONBIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,od.id,o.id,o.observationdate')
                  ->from('observationdepthattribute odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->where('odd.attributeid in ('.$str[0].')')
                  ->groupBy('o.observationdate')
                  ->orderBy('o.observationdate')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $time = strtotime($t->Observationdepth->Observation["observationdate"]);
                    $year=date('Y', $time);
                      $strtmp=$strtmp.'<option>'.$year.'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }
//
//                  else if ($str[1] =="OVERLAY")
//                  {
//                  $this->flgCitation="OVERLAY";
//                  $this->Overlaycitation=Doctrine_Query::create()
//                  ->select('ro.id,r.citation')
//                  ->from('researchoverlay ro')
//		  ->leftJoin('ro.Research r')
//                  ->where('ro.id in ('.$str[0].')')
//                  ->groupBy('r.citation')
//                  ->execute();
//                  }

            }

  }
public function executeLoadsearchresultdepths(sfWebRequest $request)
  {
     $str= explode("flag_search_loadsearchresultdepths", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
                  if ($str[1] =="BIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,od.observationdepth')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->where('odd.speciesid in ('.$str[0].')')
                  ->groupBy('od.observationdepth')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $strtmp=$strtmp.'<option>'.$t->Observationdepth["observationdepth"].'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }
                  else if ($str[1] =="NONBIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,od.observationdepth')
                  ->from('observationdepthattribute odd')
                  ->leftJoin('odd.Observationdepth od')
                  ->where('odd.attributeid in ('.$str[0].')')
                  ->groupBy('od.observationdepth')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $strtmp=$strtmp.'<option>'.$t->Observationdepth["observationdepth"].'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }



            }

  }

public function executeLoadsearchresultunits(sfWebRequest $request)
  {
     $str= explode("flag_search_loadsearchresultunits", $this->getRequestParameter('search'));


        if ($str[0] !=null && $str[0]!="")
            {
//                  if ($str[1] =="BIO")
//                  {
//                  $Bioloadsearchlocations=Doctrine_Query::create()
//                  ->select('odd.id,od.observationdepth')
//                  ->from('observationdepthdetail odd')
//                  ->leftJoin('odd.Observationdepth od')
//                  ->where('odd.speciesid in ('.$str[0].')')
//                  ->groupBy('od.observationdepth')
//                  ->execute();
//                  $strtmp="<option>All</option>";
//                  foreach ($Bioloadsearchlocations as $t)
//                  {
//                    $strtmp=$strtmp.'<option>'.$t->Observationdepth["observationdepth"].'</option>';
//                  }
//                  echo $strtmp;
//                  return sfView::NONE;
//                  }
//                  else 
                  if ($str[1] =="NONBIO")
                  {
                  $Bioloadsearchlocations=Doctrine_Query::create()
                  ->select('odd.id,u.unit')
                  ->from('observationdepthattribute odd')
                  ->leftJoin('odd.Unit u')
                  ->where('odd.attributeid in ('.$str[0].')')
                  ->groupBy('u.unit')
                  ->execute();
                  $strtmp="<option>All</option>";
                  foreach ($Bioloadsearchlocations as $t)
                  {
                    $strtmp=$strtmp.'<option>'.$t->Unit["unit"].'</option>';
                  }
                  echo $strtmp;
                  return sfView::NONE;
                  }



            }

  }
public function executePopuppie(sfWebRequest $request)
  {
      $params = "";// "375,374";
      $strtmp="";
    if ($this->getRequestParameter('search') !=null && $this->getRequestParameter('search') != "")
    {
            $this->chartDetail=Doctrine_Query::create()
                  ->select('odd.speciesid,sum(odd.quantity) as qty')
                  ->addSelect('s.species')
                  ->from('observationdepthdetail odd')
                  ->leftJoin('odd.Species s')
                  ->leftJoin('odd.Observationdepth od')
                  ->leftJoin('od.Observation o')
                  ->where('o.id In ('.$this->getRequestParameter('search').')')
                  ->groupBy('speciesid')
                  ->orderBy('sum(odd.quantity) desc')
                  ->execute();


    }

    $output="";
    foreach($this->chartDetail as $item){
        $output= $output.$item->Species["species"].":".$item["qty"]."|";

       

    }
    
    echo "BIOflgtype".$output;

    return sfView::NONE;
  }

}
